package com.yzw.course.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yzw.common.domain.EduCourse;
import com.yzw.common.dto.R;
import com.yzw.common.vo.CourseVo;
import com.yzw.common.vo.EduCourseVo;
import com.yzw.common.vo.EduPublishVo;
import com.yzw.course.service.EduCourseService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @Author Yzw
 * @Description TODO
 * @Date 2023/5/8 11:40
 * @Version 1.0
 */
@RestController
@RequestMapping("/course")
@Slf4j
public class EduCourseController {
    @Resource
    EduCourseService eduCourseService;

    @ApiOperation("根据课程id查询发布课程信息")
    @GetMapping("/getPublish/{courseId}")
    public R getPublish(@PathVariable String courseId){
        EduPublishVo eduPublishVo = eduCourseService.getPublish(courseId);
        return R.success("查询发布课程信息成功",eduPublishVo);
    }

    @ApiOperation("展示课程列表")
    @PostMapping("/page/{pageNum}/{pageSize}")
    public R selCourse(@PathVariable Integer pageNum, @PathVariable Integer pageSize, @RequestBody CourseVo courseVo) {
        log.info("课程条件" + courseVo);
        Page<EduCourse> page = eduCourseService.selCourse(pageNum,pageSize,courseVo);
        return R.success("查询成功", page);
    }

    @ApiOperation("删除课程")
    @DeleteMapping("/{id}")
    public R delete(@PathVariable Long id) {
        eduCourseService.delete(id);
        return R.success("删除成功", null);
    }

    @ApiOperation("添加课程")
    @PostMapping("/addCourse")
    public R addCourse(@RequestBody @Validated EduCourseVo eduCourseVo) {
        String id = eduCourseService.addCourse(eduCourseVo);
        return R.success("添加课程成功",id);
    }

    @ApiOperation("课程id查课程信息")
    @GetMapping("/selCourseById/{courseId}")
    public R selCourseById(@PathVariable String courseId){
        EduCourseVo eduCourseVo = eduCourseService.selCourseById(courseId);
        return R.success("查询成功",eduCourseVo);
    }

    @ApiOperation("修改课程信息")
    @PostMapping("/updCourse")
    public R updCourse(@RequestBody EduCourseVo eduCourseVo){
        eduCourseService.updCourse(eduCourseVo);
        return R.success("修改成功",null);
    }

    @ApiOperation("课程最终发布")
    @PutMapping("{courseId}")
    public R putPublish(@PathVariable String courseId){
        EduCourse eduCourse = new EduCourse();
        eduCourse.setId(courseId);
        eduCourse.setStatus("Normal");
        eduCourseService.updateById(eduCourse);
        return R.success("修改成功",null);
    }
}
